<template>
  <div class="box">
    <div class="info">
      <div class="user_img">
        <img :src="$axios.defaults.baseURL + item.user.head_img" alt="" />
      </div>
      <div class="nickname">
        {{ item.user.nickname }}
        <p class="time">2小时前</p>
      </div>
      <div class="revert" @click="callReply">回复</div>
    </div>
    <Parent
      :parentDepth="parentDepth"
      v-if="item.parent"
      :parentdata="item.parent"
    />
    <div class="content">
      {{ item.content }}
    </div>
  </div>
</template>

<script>
import Parent from "../comment/Parent";
export default {
  props: ["item"],
  components: {
    Parent,
  },
  methods: {
    callReply() {
      this.$emit("callReply", this.item.id);
      console.log(this.item.id);
    },
  },
  computed: {
    parentDepth() {
      let depth = 0;
      let current = this.item;
      while (current.parent) {
        // 每当当前节点有 parent
        // 就把深度加一, 并且将parent 设为下次的起点
        depth += 1;
        current = current.parent;
      }
      return depth;
    },
  },
};
</script>

<style lang="less" scoped>
.box {
  color: #333;
  .user_img {
    width: 35px;
    height: 35px;
  }
  .info {
    padding: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .nickname {
      margin-left: 10px;
      font-size: 14px;
      flex: 1;
    }
    .time {
      font-size: 12px;
      color: #666;
    }
  }
  img {
    width: 35px;
    height: 35px;
    border-radius: 50%;
  }
  .revert {
    font-size: 14px;
    color: #333;
  }
  .content {
    padding: 5px 20px;
    font-size: 16px;
  }
}
</style>
